package com.cn.qgx428.lazydiary.dialog

import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.Button
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextView
import com.cn.qgx428.lazydiary.R
import kotlinx.android.synthetic.main.dialog_custom_alert.*

/**
 * Created by qinguanxiong on 2018/3/11.
 */

class CustomAlertDialog : Dialog{

    lateinit var mContext: Context
    lateinit var mainView: View

    public constructor(context: Context):
            super(context){
        mContext = context
        mainView = LayoutInflater.from(mContext).inflate(R.layout.dialog_custom_alert,null)
        setContentView(mainView)
        initView()
    }

    private fun initView() {
        // 调整背景大小
        val wm = mContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        val display = wm.defaultDisplay
        alertDialog_mainLayout.layoutParams =
               FrameLayout.LayoutParams(((display.width * 0.75).toInt()),
                        LinearLayout.LayoutParams.WRAP_CONTENT)
        alertDialog_btn_neg.setOnClickListener({
            dismiss()
        })
    }

    public fun setNeg(listener: ()-> Unit){
        alertDialog_btn_neg.setOnClickListener({
            listener()
        })
    }

    public fun setPos(listener: () -> Unit){
        alertDialog_btn_pos.setOnClickListener({
            listener()
        })
    }

    public fun setPosText(msg: String){
        alertDialog_btn_pos.setText(msg)
    }

    public fun setMessage(msg: String){
        alertDialog_txt_msg.setText(msg)
    }
}
